package com.itheima;

import java.util.*;
import java.util.concurrent.Callable;

//演示Collections工具的使用
public class CollectionsDemo {
    public static void main(String[] args) {
        //创建集合对象
        test1();
    }

    private static void text0() {
        List<String> list = new LinkedList<>();
        Collections.addAll(list,"张三","李四","王五","赵六","田七");
        list.forEach(System.out::println);
        System.out.println("------------------------");
        //打乱集合元素
        Collections.shuffle(list);
        list.forEach(System.out::println);
    }

    public static void test1(){
        List<Integer> list  = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);
        //按照倒叙顺序对集合元素进行排序
        Collections.sort(list, (o1, o2) -> o2-o1);
        System.out.println("------------------------");
        list.forEach(System.out::println);
        //让学生Student  类实现Comparable接口 并做降序
        System.out.println("------------------------");
        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三",23));
        list1.add(new Student("李四",22));
        list1.add(new Student("王五",21));
        list1.add(new Student("赵六",20));
        Collections.sort(list1);
        list1.forEach(System.out::println);




    }
}
